import React from 'react';
import { isEqual, isEmpty } from 'lodash';
import {WeaErrorPage, WeaLocaleProvider, WeaTools} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import OpToolbar from '../common/OpToolbar';
import TitleTabPane from '../common/TitleTabPane';
let Base64 = ecCom.WeaTools.Base64;
import { doPrev, doNext, handleWidth } from '../../util/common';
//tab的标题组件
class Title extends React.Component {
    constructor(props) {
        super(props);
        this.setMoreHref = this.setMoreHref.bind(this);
    }
    componentDidMount() {
        const { config, tabids } = this.props;
        const { eid, header } = config.item;
        this.setMoreHref();
        handleWidth(eid,config.params.hpid,tabids.length,header.canHeadbar, header.displayPosition);
    }
    componentDidUpdate() {
        const { config, tabids } = this.props;
        const { eid, header } = config.item;
        this.setMoreHref();
        handleWidth(eid,config.params.hpid,tabids.length,header.canHeadbar, header.displayPosition);
    }
    shouldComponentUpdate(nextProps){
        return !isEqual(this.props, nextProps)
    }
    setMoreHref() {
        const { config, more, currentTab, eMoreShowType, eMoreAddress } = this.props;
        const { eid } = config.item;
        if (more && JSON.parse(more).viewType != "6") {
            window.elements_more_params[eid] = {isRouteUrl: true, paramsStr: "&eid=" + eid+"&tabid="+ currentTab, eMoreShowType: eMoreShowType, eMoreAddress: eMoreAddress};
        } else {
            window.elements_more_params[eid] = {isRouteUrl: false, paramsStr: "&eid=" + eid+"&tabid="+ currentTab, eMoreShowType: eMoreShowType, eMoreAddress: eMoreAddress};
        }
    }
    render() {
        const { currentTab, config, tabids = [], titles = [], handleRefresh, handleDelete, handleTabData, fontSizeMp, isAlwaysShow } = this.props;
        const { eid, ebaseid } = config.params;
        const { header } = config.item;
        let { fontStyle = {} } = config.item;
        if(!isEmpty(fontSizeMp)){
            fontStyle = fontSizeMp;
        }
        let className = tabids.length <= 1 && isAlwaysShow == '0' ? 'nodisplay' : '';
        if(header.displayPosition && header.displayPosition == 'bottom'){
            return <div id={ `titleContainer_${eid}` } className={`titlecontainer ${className}`}>
                <TitleTabPane ecId={`${this && this.props && this.props.ecId || ''}_TitleTabPane@xhb8m4`} datas={this.props} fontStyle={fontStyle} ebaseid={ebaseid}/>
                {!config.item.header.canHeadbar ? <OpToolbar ecId={`${this && this.props && this.props.ecId || ''}_OpToolbar@j40ybz`} config={config} clsname={className} handleRefresh={handleRefresh} handleDelete={handleDelete}/> : ''}
            </div>
        }else {
            return <div/>
        }
      }
}
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg=this.props.error && this.props.error !=="";
            return ( <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@4bprb9`} msg={ hasErrorMsg ? this.props.error : getLabel(385218,"对不起，该页面异常，请联系管理员！") } />
        );
    }
}
Title = WeaTools.tryCatch(React, MyErrorHandler, { error: "" })(Title);
export default Title;
